function QueryEle(str) {
  if (typeof str === 'string') {
    this.eles = document.querySelectorAll(str); // 类数组
  } else {
    this.eles = [str];
  }
}

function $(str) {
  return new QueryEle(str);
}

QueryEle.prototype.hide = function () {
  this.eles.forEach(item => {
    item.style.display = 'none';
  })
  return this;
}//隐藏

QueryEle.prototype.show = function () {
  this.eles.forEach(item => {
    item.style.display = 'block';
  })
  return this;
}//显示

QueryEle.prototype.click = function (fn) {
  this.eles.forEach(item => {
    item.onclick = fn;
  })
  return this;
}//点击

QueryEle.prototype.on = function (event, fn) {
  this.eles.forEach(item => {
    item.addEventListener(event, fn);
  })
  return this;
}

QueryEle.prototype.html = function (content) {

  if (!content && content != '') {
    return this.eles[0].innerHTML;
  } else { // 有参数

    this.eles.forEach(item => {
      item.innerHTML = content;
    })
  }
  return this;
}

QueryEle.prototype.val = function (content) {

  if (!content && content != '') {
    return this.eles[0].value
  } else {

    this.eles.forEach(item => {
      item.value = content;
    })

  }
  return this;
}

QueryEle.prototype.attr = function (attr, value) {

  if (value || value == '') { // 写
    this.eles.forEach(item => {
      item.setAttribute(attr, value);
    })
  } else {
    return this.eles[0].getAttribute(attr)
  }
  return this;
}

QueryEle.prototype.css = function (property, value) {
  if (!value) {
    if (typeof property === 'string') {
      if (getComputedStyle) {
        return getComputedStyle(this.eles[0], false)[property]
      } else {
        return this.eles[0].currentStyle[property]
      }
    } else {
      this.eles.forEach(item => {
        for (var key in property) {
          item.style[key] = property[key];
        }
      })
    }
  } else {
    this.eles.forEach(item => {
      item.style[property] = value;
    })
  }
  return this;
}

QueryEle.prototype.siblings = function () {
  var children = this.eles[0].parentNode.children;
  var list = [];
  for (var i = 0; i < children.length; i++) {
    if (children[i] != this.eles[0]) {
      list.push(children[i]);
    }
  }

  this.eles = list;

  return this;
}

QueryEle.prototype.index = function () {
  var children = this.eles[0].parentNode.children;
  for (var i = 0; i < children.length; i++) {
    if (children[i] == this.eles[0]) {
      return i;
    }
  }
}

QueryEle.prototype.eq = function (index) {

  // return $(this.eles[index])

  this.eles = [this.eles[index]];

  return this;

}
